package com.heima.zuoye.day12.timu2;

import java.lang.reflect.MalformedParameterizedTypeException;
import java.util.concurrent.locks.ReentrantLock;

public class Demo1 {
    public static void main(String[] args) {
        Mp m1 = new Mp();
        Mp m2 = new Mp();
        Mp m3 = new Mp();
        m1.start();
        m2.start();
        m3.start();
    }
}

class Mp extends Thread {
    private final Object object = new Object();
    ReentrantLock lk = new ReentrantLock();

    @Override
    public void run() {
        int p = 100;
        while (true) {
            lk.lock();
            try {
                if (p <= 0) {
                    break;
                } else {
                    p--;
                    System.out.println(Thread.currentThread().getName() + ":" + p);
                }
            } catch (Exception e){
                e.printStackTrace();
            } finally {
                lk.unlock();
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
